﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using PPI.Entities.Polygon;

namespace PPIControls.Map
{
    public partial class SelectMaps : UserControl
    {
        private List<EUtility_Polygon> m_Polygons;

        public SelectMaps()
        {
            InitializeComponent();
        }

        private void SelectMaps_Load(object sender, EventArgs e)
        {
            chkSelectAll_CheckedChanged(this,new EventArgs());
        }

        public void LoadMaps(List<EUtility_Polygon> maps)
        {
            foreach (EUtility_Polygon map in maps)
            {
                CheckBoxItem tmpCheckbox = new CheckBoxItem("chk_"+map.Id,map.Name);
                tmpCheckbox.Tag = map;
                itmContainerMaps.Items.Add(tmpCheckbox);
            }
        }

        public List<EUtility_Polygon> GetSelectedMaps()
        {
            List<EUtility_Polygon> selectedMaps = new List<EUtility_Polygon>();
            foreach (BaseItem item in itmContainerMaps.Items)
            {
                CheckBoxItem tmpCheckbox = (CheckBoxItem) item;
                if(tmpCheckbox.Checked)
                    selectedMaps.Add((EUtility_Polygon)tmpCheckbox.Tag);
            }
            return selectedMaps;
        }

        public void ClearMaps()
        {
            itmContainerMaps.Items.Clear();
        }

        private void chkSelectAll_CheckedChanged(object sender, EventArgs e)
        {
            foreach (BaseItem item in itmContainerMaps.Items)
            {
                CheckBoxItem tmpCheckbox = (CheckBoxItem)item;
                tmpCheckbox.Checked = chkSelectAll.Checked;
            }
        }
    }
}
